package org.bp.ioc.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

public final class CodecUtils {
    private static final Logger LOGGER = LoggerFactory.getLogger(CodecUtils.class);

    public static String encoderURL(String source){
        try {
            return URLEncoder.encode(source,"utf-8");
        } catch (UnsupportedEncodingException e) {
            LOGGER.error("encoderURL failed",e);
            throw new RuntimeException(e);
        }
    }

    public static String decoderURL(String source){
        try {
            return URLDecoder.decode(source,"utf-8");
        } catch (UnsupportedEncodingException e) {
            LOGGER.error("decoderURL failed",e);
            throw new RuntimeException(e);
        }
    }
}
